package com.csjbot.weedle_auto.fragment.util

import com.csjbot.weedle_auto.Slam.agent.RPSlamwareSdpAgent
import com.orhanobut.logger.Logger

/**
 * Created by chenqi on 8/10/17.
 */

object ShareConstants {
    /**
     * 每隔三十秒更新slam的机器人状态和地图数据
     */
    fun GetAgentUpdate(agent: RPSlamwareSdpAgent) {
        Thread(object : Runnable {
            private var cnt: Int = 0
            override fun run() {
                cnt = 0
                while (true) {
                    //                    if (robotStateUpdateThread == null || !robotStateUpdateThread.isAlive() ||
                    //                            robotStateUpdateThread.isInterrupted()) {
                    //                        isRobotStateUpdating = false;
                    //                        return;
                    //                    }
                    if (cnt % 60 == 0) {
                        agent.updatePose()
                        //                        agent.updateMoveAction();
                    }

                    if (cnt % 120 == 0) {
                        agent.updateRobotStatus()
                        agent.getRobotHealth()
                    }

                    //                    if ((cnt % 15) == 0) {
                    //                        agent.updateLaserScan();
                    //                        agent.updateWalls();
                    //                    }

                    //                    synchronized (this) {
                    //                        if (!(cnt % 30 == 0)) {
                    //                            agent.updateMap();
                    //                        }
                    //                    }
                    cnt++
                    try {
                        Thread.sleep(33)
                        //   Pose pose = agent.getRobotPose();
                        //                        Logger.d("chenqi " + "x" + pose.getX()+
                        //                                "y" + pose.getY()+
                        //                                "z" + pose.getZ()+
                        //                                "yaw"+pose.getYaw()
                        //                            );
                    } catch (e: Exception) {
                        Logger.d("robot state update thread interrupted")
                    }

                }
            }
        }).start()
    }
}
